let optionInit = function(fsData){
	const upColor = '#4eb76c';		//绿
	const downColor = '#e64b4b';      //红
	const data = splitFsData(fsData);
    const titInfo = fsData['hq.fsbase'][0];

	let options = {
        backgroundColor: '#fff',
        animation: false,
        title: {
            text: titInfo.name + '[' + titInfo.code + ']' + ' ' + titInfo.hqda,
            textStyle: {
                fontSize: '18px'
            },
            left: '12%'
        },
        // tooltip: {
        //     trigger: 'axis',
        //     axisPointer: {
        //         type: 'cross'
        //     },
        //     backgroundColor: 'rgba(245, 245, 245, 0.8)',
        //     borderWidth: 1,
        //     borderColor: '#ccc',
        //     padding: 10,
        //     textStyle: {
        //         color: '#000'
        //     },
        //     position: function (pos, params, el, elRect, size) {
        //         var obj = {top: 10};
        //         obj[['left', 'right'][+(pos[0] < size.viewSize[0] / 2)]] = 30;
        //         return obj;
        //     }
        // },
        axisPointer: {
            link: {xAxisIndex: 'all'},
            label: {
                backgroundColor: '#777'
            }
        },
    	visualMap: {
            show: false,
            seriesIndex: 2,
            dimension: 2,
            pieces: [{
                value: 1,
                color: downColor
            }, {
                value: -1,
                color: upColor
            }]
        },
        grid: [
            {
                left: '12%',
                right: '4%',
                top: 25,
                height: '55%'
            },
            {
                left: '12%',
                right: '4%',
                top: '75%',
                height: '16%'
            }
        ],
        // grid: [
        //     {
        //         left: '10%',
        //         right: '8%',
        //         top: '8%',
        //         height: '50%'
        //     },
        //     {
        //         left: '10%',
        //         right: '8%',
        //         top: '75%',
        //         height: '20%'
        //     }
        // ],
        xAxis: [
            {
                type: 'category',
                data: data.categoryData.map(item => {
                  let tar = item + ''
                  let str = tar.slice(-2)
                  let s = tar.replace(str, ":"+str)
                    return s;
                }),
                boundaryGap : false,
                axisLine: {onZero: false},
                axisTick: {show: false},
                splitLine: {
                  show: true,
                  lineStyle: {
                    type: 'dashed'
                  }
                },
                axisLabel: {
                  formatter: function (value, index) {
                    if(index == 0){
                      return
                    }
                    return value
                  }
                },
                min: 'dataMin',
                max: 'dataMax',
                axisPointer: {
                    z: 100
                }
            },
            {
                type: 'category',
                gridIndex: 1,
                data: data.categoryData.map(item => {
                  let tar = item + ''
                  let str = tar.slice(-2)
                  let s = tar.replace(str, ":"+str)
                    return s;
                }),
                boundaryGap : false,
                axisLine: {onZero: false},
                axisTick: {show: false},
                splitLine: {
                  show: true,
                  lineStyle: {
                    type: 'dashed'
                  }
                },
                axisLabel: {show: false},
                min: 'dataMin',
                max: 'dataMax'
            }
        ],
        yAxis: [
            {
                scale: true,
                axisTick: {show: false},
                splitArea: {
                    show: false
                },
                min: function(value) {
                  return parseFloat(value.min*0.997).toFixed(2)
                },
                max: function(value) {
                    return parseFloat(value.max*1.003).toFixed(2)
                }
            },
            {
                scale: true,
                axisTick: {show: false},
                gridIndex: 1,
                splitNumber: 2,
                type : 'value',
                show:true,
                axisLine:{
                    show:true,
                    lineStyle: {
                        width: 0.5
                    }
                },
                axisLabel: {
                    show:true,
                    formatter: function (v) {
                      if (v > 1000000) {
                          return (v / 1000000).toFixed(1) + ' 万'
                      } else {
                          return (v/100).toFixed(1);
                      }
                    }
                },
                splitLine: { show:true }
            }
        ],
        series: [
            {
                name:'均线',
                type:'line',
                symbol: 'none',
                data:data.averageData,
                itemStyle:{
                    normal:{
                        lineStyle:{
                            width:1,
                            color:'#ffc100',
                            type:'solid'
                        }
                    }
                }
            },
            {
                name:'分时k线',
                type:'line',
                symbol: 'none',
                data:data.values,
                itemStyle:{
                    normal:{
                        areaStyle: {
                            color: '#eeeef0'
                        },
                        lineStyle:{
                            width:1,
                            color:'#178cea',
                            type:'solid'
                        }
                    }
                }
            },
            {
                name: 'Volume',
                type: 'bar',
                xAxisIndex: 1,
                yAxisIndex: 1,
                data: data.volumes
            }
        ]
	}
	return options
}


var splitFsData = function(tar) {
	let rawData = tar['hq.fs']
	let fsbase = tar['hq.fsbase']
	let jrkp = fsbase[0].jrkp
    var categoryData = []
    var values = []
    var volumes = []
    var averageData = []
    rawData.forEach((item, index) => {
    	categoryData.push(item.hqtm);
        values.push(item.zjcj);
        volumes.push([index, item.cjsl, item.zjcj > jrkp ? 1 : -1]);
        averageData.push(item.cjjj)
    })
    return {
        categoryData: categoryData,  //["931", "932"]
        values: values,   			 //[11.830000, 11.830000, 11.830000]
        volumes: volumes,   		 //[0, 168890000, 1]
        averageData: averageData	 //[11.817637, 11.817637 11.830000]
    }
}

export default optionInit;
